import { Component, OnInit, Injector, ViewChild, Output, EventEmitter, ElementRef } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import {
    EditDtoExtensionsItem,
    Stock_IntoMarketItemEditDto
} from '@shared/service-proxies/stock-service-proxies';
import { ModalDirective } from 'ngx-bootstrap';

@Component({
    selector: 'marketBaseInfoModal',
    templateUrl: './market-base-info-modal.component.html'
})
export class MarketBaseInfoModalComponent extends AppComponentBase {
    constructor(injector: Injector) {
        super(injector);
    }

    @ViewChild('createOrEditModal') modal: ModalDirective;
    @ViewChild('createOrEditModal') modalEl: ElementRef;

    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
    @Output() insertId: EventEmitter<any> = new EventEmitter<any>();
    active = false;
    saving = false;
    closed = false;

    editDto: Stock_IntoMarketItemEditDto;
    extensions: Array<EditDtoExtensionsItem>;
    optionAll;

    show(): void {
        this.active = true;
        this.closed = false;
        this.modal.show();
      
    }

    close(): void {
        this.active = false;
        this.modal.hide();
    }

    onHidden(event) {
        this.closed = true;
    }

    rowSelect(event) {
        this.close();
        // this.modalEl.nativeElement.
        // (this.modalEl.nativeElement as any).hasClass

        let timer = setInterval(() => {
            if (this.closed) {
                this.modalSave.emit(event);
      
                clearInterval(timer);
            }
        }, 50);
    }
}
